﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BL.Membership;
using BaseLib.Security;

namespace DA
{
    public static class ClientExtensions
    {
        private const int CLIENTS_ENCRYPTION_KEY = 3;

        public static UserPermission GetPermissions(this Client client)
        {
            long perms;
            AESEncryption encryption = new AESEncryption(CLIENTS_ENCRYPTION_KEY);
            string number = encryption.DecryptString(client.PermissionsString);

            UserPermission permissions = UserPermission.None;

            if (long.TryParse(number, out perms))
                permissions = (UserPermission)perms;

            return permissions;
        }

        public static void SetPermissions(this Client client, UserPermission perm)
        {
            AESEncryption encryption = new AESEncryption(CLIENTS_ENCRYPTION_KEY);
            client.PermissionsString = encryption.EncryptToString(((long)perm).ToString());
        }
    }
}
